$(function () {
    var data = window.location.search.substring(1);
    var decodeData = decodeURIComponent(window.atob(data));
    var url = "/rentCart!selectItem";

    sendRequest("post",url,decodeData,showResult);
    //console.log(decodeData);
});
var custStr;
var customer;
var proInfo;

function showResult(data) {

    var proStr = eval("("+ data +")");


    //console.log(proStr);
    //console.log(proInfo);
    if(proStr != "select_fail"){
        proInfo = eval("("+ proStr +")");
        //alert(proStr);
        //console.log(proInfo);
        //显示图片
        $(".hairstyle_main .hairstyle_main_b .hairstyle_main_l").html("<img src=\"data:image/jpg;base64,"+ proInfo.productPhoto+"\" alt=\"\">");
        //显示商品信息
        $(".jishi_content2").html("<p class=\"t_primary14\" style=\"margin-top:4px;\">"+ proInfo.productName +"<span class=\"course_5\" style=\"position: absolute; bottom:15px; left:138px;\">￥"+ proInfo.rentPrice +"/天  &nbsp;押金:"+ proInfo.rentMoney +"元<span style=\"font-size: 13px;\"></span></span></p> \n" +
            "      \t\t\t\t\t <p style=\"margin-top: 10px;\"><span style=\"margin-right: 20px;\">颜色："+ proInfo.productColor +"</span></p> \n" +
            "      \t\t\t\t\t <p><span>数量： 1 个</span></p> \n") ;
     //     "       \t\t\t\t\t<p style=\"width: 90%; overflow: hidden;text-overflow:ellipsis;white-space:nowrap;\">品牌："+ proInfo.productType +" </p> ");
        //显示租金
        $(".rent font").html(proInfo.rentMoney + "元");
        //显示起租日期
        $("#date").val(proInfo.rentTime);
        //显示天数
        $("#days").val(proInfo.rentDays);
        custStr = localStorage.getItem("customer");
        customer = eval("("+ custStr +")");
        if(customer != null){
            //封装客户信息
            console.log(custStr);
            $("#custName").val(customer.custName);
            $("#custPhone").val(customer.custPhone);
            $("#address").val(customer.consigeeAddr);
        }
    }
    else{
        alert("该商品可能已经报废,请返回主页!");
        window.location.href = "/index.html"
    }
}

function updateRentCart() {
    //封装修改后的租物车信息
    //客户
    var jsonStr = "{\"custPhone\": \""+ $('#custPhone').val() +"\",\"accountNo\":\""+ customer.accountNo +"\",\"productQR\":\""+ proInfo.productQR +"\",\"rentDays\":"+ $('#days').val() +",\"price\":"+ $("#days").val()*proInfo.rentPrice +",\"rentTime\":\""+ $('#date').val() +"\"}";
    var url = "/rentCart!update";
    var data = "cartStr=" + jsonStr;
    sendRequest("post",url,data,updateBack);
}

function updateBack(data) {
    if(data == "\"update_success\""){
        alert("修改成功！");
        window.location.href = "rentCart.html";
    }
    if(data == "\"update_fail\""){
        alert("修改失败！");
    }
}